home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / shaolins.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  169 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. unsigned char *shaolins_scroll;
  14. static int palettebank;
  15.  
  16.  
  17.  
  18. /***************************************************************************
  19.  
  20.   Convert the color PROMs into a more useable format.
  21.  
  22.   Shao-lin's Road has three 256x4 palette PROMs (one per gun) and two 256x4
  23.   lookup table PROMs (one for characters, one for sprites).
  24.   I don't know for sure how the palette PROMs are connected to the RGB
  25.   output, but it's probably the usual:
  26.  
  27.   bit 3 -- 220 ohm resistor  -- RED/GREEN/BLUE
  28.         -- 470 ohm resistor  -- RED/GREEN/BLUE
  29.         -- 1  kohm resistor  -- RED/GREEN/BLUE
  30.   bit 0 -- 2.2kohm resistor  -- RED/GREEN/BLUE
  31.  
  32. ***************************************************************************/
  33. void shaolins_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  34. {
  35.     int i;
  36.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  37.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  38.  
  39.  
  40.     for (i = 0;i < Machine->drv->total_colors;i++)
  41.     {
  42.         int bit0,bit1,bit2,bit3;
  43.  
  44.  
  45.         bit0 = (color_prom[0] >> 0) & 0x01;
  46.         bit1 = (color_prom[0] >> 1) & 0x01;
  47.         bit2 = (color_prom[0] >> 2) & 0x01;
  48.         bit3 = (color_prom[0] >> 3) & 0x01;
  49.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  50.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  51.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  52.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  53.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  54.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  55.         bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  56.         bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  57.         bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  58.         bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  59.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  60.  
  61.         color_prom++;
  62.     }
  63.  
  64.     color_prom += 2*Machine->drv->total_colors;
  65.     /* color_prom now points to the beginning of the character lookup table */
  66.  
  67.  
  68.     /* there are eight 32 colors palette banks; sprites use colors 0-15 and */
  69.     /* characters 16-31 of each bank. */
  70.     for (i = 0;i < TOTAL_COLORS(0)/8;i++)
  71.     {
  72.         int j;
  73.  
  74.  
  75.         for (j = 0;j < 8;j++)
  76.             COLOR(0,i + j * TOTAL_COLORS(0)/8) = (*color_prom & 0x0f) + 32 * j + 16;
  77.  
  78.         color_prom++;
  79.     }
  80.  
  81.     for (i = 0;i < TOTAL_COLORS(1)/8;i++)
  82.     {
  83.         int j;
  84.  
  85.  
  86.         for (j = 0;j < 8;j++)
  87.         {
  88.             /* preserve transparency */
  89.             if ((*color_prom & 0x0f) == 0) COLOR(1,i + j * TOTAL_COLORS(1)/8) = 0;
  90.             else COLOR(1,i + j * TOTAL_COLORS(1)/8) = (*color_prom & 0x0f) + 32 * j;
  91.         }
  92.  
  93.         color_prom++;
  94.     }
  95. }
  96.  
  97.  
  98.  
  99. WRITE_HANDLER( shaolins_palettebank_w )
  100. {
  101.     if (palettebank != (data & 7))
  102.     {
  103.         palettebank = data & 7;
  104.         memset(dirtybuffer,1,videoram_size);
  105.     }
  106. }
  107.  
  108.  
  109.  
  110. /***************************************************************************
  111.  
  112.   Draw the game screen in the given osd_bitmap.
  113.   Do NOT call osd_update_display() from this function, it will be called by
  114.   the main emulation engine.
  115.  
  116. ***************************************************************************/
  117. void shaolins_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  118. {
  119.     int offs;
  120.     int sx,sy;
  121.  
  122.     /* for every character in the Video RAM, check if it has been modified */
  123.     /* since last time and update it accordingly. */
  124.     for (offs = 0;offs <= videoram_size;offs++)
  125.     {
  126.         if (dirtybuffer[offs])
  127.         {
  128.             dirtybuffer[offs] = 0;
  129.  
  130.             sx = offs % 32;
  131.             sy = offs / 32;
  132.  
  133.             drawgfx(tmpbitmap,Machine->gfx[0],
  134.                     videoram[offs] + ((colorram[offs] & 0x40) << 2),
  135.                     (colorram[offs] & 0x0f) + 16 * palettebank,
  136.                     0,colorram[offs] & 0x20,
  137.                     8*sx,8*sy,
  138.                     0,TRANSPARENCY_NONE,0);
  139.         }
  140.     }
  141.  
  142.  
  143.     /* copy the temporary bitmap to the screen */
  144.     {
  145.         int scroll[32], i;
  146.  
  147.         for (i = 0;i < 4;i++)
  148.             scroll[i] = 0;
  149.         for (i = 4;i < 32;i++)
  150.             scroll[i] = -*shaolins_scroll-1;
  151.         copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  152.     }
  153.  
  154.  
  155.     for (offs = spriteram_size-32; offs >= 0; offs-=32 ) /* max 24 sprites */
  156.     {
  157.         if (spriteram[offs] && spriteram[offs+6]) /* stop rogue sprites on high score screen */
  158.         {
  159.             drawgfx(bitmap,Machine->gfx[1],
  160.                     spriteram[offs+8],
  161.                     (spriteram[offs+9] & 0x0f) + 16 * palettebank,
  162.                     !(spriteram[offs+9] & 0x40),(spriteram[offs+9] & 0x80),
  163.                     240-spriteram[offs+6],248-spriteram[offs+4],
  164.                     &Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  165.                     /* transparency_color, otherwise sprites in test mode are not visible */
  166.         }
  167.     }
  168. }
  169.